$(function(){
    Ext.onReady(function() {
        var obj = {
            account: '',
            toolBar: null,
            grid: null,
            init: function () {
                var that = this;
                that.account = localStorage.getItem('account') || '';
                if(!that.account){
                    Ext.MessageBox.alert('温馨提示', '账户信息过期，请重新登录！');
                    window.location.replace('./mobileLogin.html');
                    return;
                }
                // demo数据开始，下方可删除
                var columns = [
                    {
                        "id": "2",
                        "phone": "15857502013",
                        "userName": "冯翔",
                        "age": "24",
                        "sex": "男",
                        "xl": "本科",
                        "jobType": "餐饮",
                        "earn": "4000",
                        "hy": "dv"
                    }
                ];
                that.initExtList() // 不传参数 请求接口
            },
            initExtList: function (data) {
                var that = this;
                Date.monthNames=["一月", "二月", "三月", "四月", "五月", "六月","七月","八月","九月","十月","十一月","十二月"];
                Date.dayNames = ["日", "一", "二", "三", "四", "五", "六"];

                if (Ext.DatePicker) {
                    Ext.apply(Ext.DatePicker.prototype, {
                        todayText : "今天",
                        minText : "日期在最小日期之前",
                        maxText : "日期在最大日期之后",
                        disabledDaysText : "",
                        disabledDatesText : "",
                        monthNames : Date.monthNames,
                        dayNames : Date.dayNames,
                        nextText : '下月 (Control+Right)',
                        prevText : '上月 (Control+Left)',
                        monthYearText : '选择一个月 (Control+Up/Down 来改变年)',
                        todayTip : "{0} (Spacebar)",
                        okText : "确定",
                        cancelText : "取消",
                        format : "y年m月d日"
                    });
                }
                var hy = Ext.create("Ext.data.Store",{
                    fields: ['name', 'id'],
                    data:[
                        {name:'全部',id:'全部'},
                        {name:'加工',id:'加工'},
                        {name:'商务',id:'商务'},
                        {name:'培训',id:'培训'},
                        {name:'美食',id:'美食'},
                        {name:'家居',id:'家居'},
                        {name:'卖场',id:'卖场'},
                        {name:'房产',id:'房产'},
                        {name:'汽车',id:'汽车'},
                        {name:'机构',id:'机构'},
                        {name:'医疗',id:'医疗'},
                        {name:'婚假',id:'婚假'},
                        {name:'娱乐',id:'娱乐'},
                        {name:'家政',id:'家政'}
                    ]
                });
                var store = Ext.create("Ext.data.Store",{
                    fields: ['id', 'phone','userName','age','sex','age','xl','earn','hy','jobType'],
                    data:data
                });
                if(!data){
                    // 接口请求
                    store = Ext.create("Ext.data.Store", {
                        fields: ['id', 'phone','userName','age','sex','age','xl','earn','hy','jobType'],
                        autoLoad: true,
                        pageSize: 20, // 一页 20条
                        proxy: {
                            type: 'ajax',
                            url: $.getAjaxHost('def') + 'zpinfo/applicantMsgList',
                            method : 'POST',
                            params: {
                                account: localStorage.getItem('account')
                            },
                            // page 第几页 1
                            // start 开始页 0开始
                            // limit 页面大小
                            reader: {
                                type: 'json',
                                root: 'list',
                                totalProperty: 'total' // 总数对应字段名称
                            }
                        }
                    });
                }
                that.grid = new Ext.grid.GridPanel({
                    renderTo: document.body,
                    title: '人才登记列表',
                    width: '100%',
                    height: '100vh',
                    autoHeight : true,
                    stripeRows: true,
                    loadMask:true,
                    autoExpandColumn: 'id',
                    stateful: true,
                    stateId: 'grid',
                    layout: 'fit',
                    fullscreen: true,
                    columns: [
                        { text: '编号', dataIndex: 'id', width: 50,sortable : true },
                        { text: '姓名', dataIndex: 'userName', width: 120,sortable : true },
                        { text: '电话', dataIndex: 'phone', width: 120,sortable : true },
                        { text: '年龄', dataIndex: 'age', width: 120,sortable : true },
                        { text: '性别', dataIndex: 'sex', width: 150,sortable : true },
                        { text: '行业', dataIndex: 'hy', width: 80,sortable : true },
                        { text: '学历', dataIndex: 'xl', width: 80,sortable : true },
                        { text: '希望酬薪', dataIndex: 'earn', width: 150,sortable : true },
                        { text: '希望工种', dataIndex: 'jobType', width: 150,sortable : true },
                    ],
                    store: store,
                    tbar: [
                        "行业:",
                        {
                            xtype:'combobox',
                            id: 'searchHyBar',
                            queryMode:'local',//[local|remot]
                            store:hy,
                            valueField:"id",
                            displayField :'name',
                            value:'全部',
                            forceSelection : true,
                        },
                        "登记时间:",
                        {
                            xtype: 'datefield',
                            id: 'searchBDateBar',
                            format : 'Y-m-d',

                            endDateField: 'searchEDateBar',
                        },"至",
                        {
                            xtype: 'datefield',
                            id: 'searchEDateBar',
                            format : 'Y-m-d',
                            startDateField: 'searchBDateBar',

                        }, {
                            xtype: 'button',
                            text: "搜索",
                            handler: function() {
                                var hy = Ext.getCmp("searchHyBar").getValue()
                                store.proxy.extraParams.hy = hy === '全部'?'':hy;
                                store.proxy.extraParams.BDate = Ext.getCmp("searchBDateBar").getValue().getTime();
                                store.proxy.extraParams.EDate = Ext.getCmp("searchEDateBar").getValue().getTime()+8639999;
                                store.page = 1;
                                store.pageSize = 20;
                                that.grid.store = store;
                                that.grid.store.reload()
                            }
                        }
                    ],
                    bbar : {
                        xtype : 'pagingtoolbar',
                        store: store,
                        pageSize: 20,
                        displayInfo: true,
                        displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
                        emptyMsg: "没有数据"
                    }

                });
            }
        };
        obj.init();
    });
});